package com.han.transfer.util;

import java.util.Random;

/**
 * @author HanJiafeng
 * @date 2021/6/9 16:21
 * @desc todo
 */
public class TransferUtil {
    /**
     * 生成转账id
     *
     * @param transferTime 转账时间
     * @return 转账id
     */
    public static String generateTransferId(String transferTime) {

        StringBuilder transferNumberBuilder = new StringBuilder("1000");

        String[] firstNumbers = {"107101", "049901"};
        Random random = new Random();
        int r = random.nextInt(10);
        String firstNumber = firstNumbers[0];
        if (r > 6) {
            firstNumber = firstNumbers[1];
        }
        transferNumberBuilder.append(firstNumber);

        String timeStr = transferTime.substring(0, 10).replace("-", "")
                .replace(":", "");
        transferNumberBuilder.append(timeStr);

        //尾部14位数字
        StringBuilder tailBuilder = new StringBuilder();
        for (int i = 0; i < 14; i++) {
            int tempInt = random.nextInt(10);
            tailBuilder.append(tempInt);
        }
        transferNumberBuilder.append(tailBuilder);
        if (transferNumberBuilder.charAt(transferNumberBuilder.length() - 1) != '1') {
            transferNumberBuilder.replace(transferNumberBuilder.length() - 2, transferNumberBuilder.length() - 1, "1");
        }
        return transferNumberBuilder.toString();
    }
}
